<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>自定选项</title>
    <script type="text/javascript">
    	var dialog;
        var gridManager = null;
        $(function (){
        	$(".l-toolbar-item").hover(
        		function (){
                	$(this).addClass("l-panel-btn-over");
            }, function (){
                	$(this).removeClass("l-panel-btn-over");
            });
        	
        	$(".l-toolbar-item").click(function(){
        		toolbarBtnItemClick($(this));
        	});

            $("#maingrid").ligerGrid({
                columns: [
                { display: '代码', name: 'thId', align: 'left', width:'20%', minWidth: 60 },
                { display: '定义', name: 'thName', width:'20%',minWidth: 120 },
                { display: '代码长度', name: 'thWidth', width:'35%',minWidth: 120 },
                { display: '启用', width:'10%', name: 'isEnable',
                    editor: { type: 'chk'},
                    render: function (item)
                    {
                        if (item.isEnable=='F'){
                        	return '<input type="checkbox" name="isEnable" onclick="changeTnfToStore(this,\''+item.thId+'\',\'${ctx}/tab/changeEnable\')"/>';
                        }
                        return '<input type="checkbox" name="isEnable" checked="checked" onclick="changeTnfToStore(this,\''+item.thId+'\',\'${ctx}/tab/changeEnable\')"/>';
                    }
                }
                ], dataAction: 'server', url: '${ctx}/tab/list', sortName: 'thId',
                width: '100%', height: '100%', numPerPage:20,rownumbers:true,
                checkbox : true,
                heightDiff: -6
            });
             
            gridManager = $("#maingrid").ligerGetGridManager();

            $("#pageloading").hide();
        });

        function search(){
            if (!gridManager) return;
            var thId = $("#thId").val(); 
            var thName = $("#thName").val(); 
            gridManager.setOptions(
                { parms: [{ name: 'search_LIKE_thName', value: thName},{ name: 'search_LIKE_thId', value: thId}] }
            );
            gridManager.loadData(true);
        }
        
        function toolbarBtnItemClick(item) {
            switch (item.attr("toolbarid")) {
                case "add":
                	dialog=$.ligerDialog.open({url: '${ctx}/tab/view/add?thId=',height:450, width:900, showMax: true, showToggle: true, showMin: true, isResize: true, modal: true, title:"添加"});
                    break;
                case "detail":
                    var row = gridManager.getSelected();
                    if (!row){
                    	alert('请选择行');
                    }else{
                    	dialog=$.ligerDialog.open({url: '${ctx}/tab/view/detail?thId='+row.thId,height:450, width:900, showMax: true, showToggle: true, showMin: true, isResize: true, modal: true, title:"详细"});
                    }
                    break;
                case "modify":
                    var row = gridManager.getSelected();
                    if (!row){
                    	alert('请选择行');
                    }else{
                    	dialog=$.ligerDialog.open({url: '${ctx}/tab/view/modify?thId='+row.thId,height:450, width:900, showMax: true, showToggle: true, showMin: true, isResize: true, modal: true, title:"修改"});
                    }
                    break;
                case "delete":
                    $.ligerDialog.confirm('确定删除吗?', function (confirm) {
                        if (confirm)
                            remove();
                    });
                    break;
            }
        }

        function reload(){
        	gridManager.loadData();
        }
        function remove(){
        	var rows=gridManager.getCheckedRows();
            if (rows) {
            	var rowIds="";
            	for(var i=0;i<rows.length;i++){
            		rowIds+=rows[i].thId+",";
            	}
                LG.ajax({
                    url: '${ctx}/tab/delete',
                    loading: '正在删除中...',
                    data:{ids:rowIds},
                    success: function (result) {
                        LG.showSuccess(result.message);
                        reload();
                    },
                    error: function (result) {
                        LG.showError(result.message);
                    }
                });
            }
            else {
                LG.tip('请选择行!');
            }
        }
        function saveDoneCallBack(){
        	dialog.close();
            gridManager.loadData(true);
        }
    </script>
</head>
<body style="padding:0px; overflow:hidden;"> 
<div class="l-loading" style="display:block" id="pageloading"></div> 

<div style=" width:100%" id="mainsearch">
    <div class="searchtitle">
        <span>搜索</span>
        <img src="${ctx}/static/icons/32X32/searchtool.gif"/>
        <div class="togglebtn"></div> 
    </div>
    <div style="margin-bottom:4px; margin-top:4px;" class="navline"></div>
    <div class="searchbox">
        <form class="l-form" id="formsearch" ligeruiid="formsearch">
        	<ul>
        		<li style="width:90px;text-align:left;">代码：</li>
        		<li style="width:180px;text-align:left;">
	        		<div class="l-text" style="width: 178px;">
	        			<input type="text" ligerui="{&quot;width&quot;:178}" id="thId" ltype="text" class="field l-text-field" style="width: 174px;">
	        			<div class="l-text-l"></div>
	        			<div class="l-text-r"></div>
	        		</div>
        		</li>
        		<li style="width:40px;"></li>
        		<li style="width:90px;text-align:left;">定义：</li>
        		<li style="width:180px;text-align:left;">
	        		<div class="l-text" style="width: 178px;">
	        			<input type="text" ligerui="{&quot;width&quot;:178}" id="thName" ltype="text" class="field l-text-field" style="width: 174px;">
	        			<div class="l-text-l"></div>
	        			<div class="l-text-r"></div>
	        		</div>
        		</li>
        		<li style="width:40px;"></li>
        		<li style="margin-right:8px">
        			<div style="width:60px" class="button button2 buttonnoicon" onclick="search()">
	        			<div class="button-l"> </div>
	        			<div class="button-r"> </div> 
	        			<span>查询</span>
        			</div>
        		</li>
        	</ul>
        	<div class="l-clear"></div>
        </form>
    </div>
</div>

<div class="l-panel-topbar l-toolbar" ligeruiid="ToolBar1000">
	<div class="l-toolbar-item l-panel-btn l-toolbar-item-hasicon" toolbarid="add">
		<span>新增</span>
		<div class="l-panel-btn-l"></div>
		<div class="l-panel-btn-r"></div>
		<img src="${ctx}/static/icons/silkicons/add.png">
	</div>
	<div class="l-bar-separator"></div>
	<div class="l-toolbar-item l-panel-btn l-toolbar-item-hasicon" toolbarid="modify">
		<span>修改</span>
		<div class="l-panel-btn-l"></div>
		<div class="l-panel-btn-r"></div>
		<img src="${ctx}/static/icons/silkicons/application_edit.png">
	</div>
	<div class="l-bar-separator"></div>
	<div class="l-toolbar-item l-panel-btn l-toolbar-item-hasicon" toolbarid="delete">
		<span>删除</span>
		<div class="l-panel-btn-l"></div>
		<div class="l-panel-btn-r"></div>
		<img src="${ctx}/static/icons/silkicons/delete.png">
	</div>
	<div class="l-bar-separator"></div>
	<div class="l-toolbar-item l-panel-btn l-toolbar-item-hasicon" toolbarid="detail">
		<span>查看</span>
		<div class="l-panel-btn-l"></div>
		<div class="l-panel-btn-r"></div>
		<img src="${ctx}/static/icons/silkicons/application_view_detail.png">
	</div>
	<div class="l-bar-separator"></div>
</div>

<div id="maingrid" style="margin:0; padding:0"></div>

<div style="display:none;"></div>
 
</body>
</html>
